package com.osdp.sc.controller;

import com.alibaba.fastjson.JSONObject;
import com.osdp.sc.service.IScRoleUserService;
import com.osdp.sc.vo.ScRoleUserVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户角色关系管理")
@RestController
//@RefreshScope
@RequestMapping("/uc/userRole")
public class ScRoleUserController {

    @Autowired
    private IScRoleUserService userRoleService;

    @RequestMapping(value = "/queryUserRoleByRoleId", method = RequestMethod.GET)
    public List<ScRoleUserVo> queryUserRoleByRoleId(@RequestParam(name = "roleId", required = true) String roleId){
        return userRoleService.queryUserRoleByRoleId(roleId);
    }

    @PostMapping("/saveUserRoleByRoleId")
    public boolean saveUserRoleByRoleId(@RequestBody JSONObject jsonObject){
        String roleId = jsonObject.getString("roleId");
        List<String> userIds = null;
        if(jsonObject.containsKey("userIds")) {
            userIds = jsonObject.getJSONArray("userIds").toJavaList(String.class);
        }
        return userRoleService.batachSaveOrUpdateUserRoleByRoleId(roleId,userIds);
    }
}
